rm(list = ls())

set.seed(1917)

# load relevant packages
source("00_pckgs.R")

# at times, the r session may crash for reasons unrelated to this code.
# in an initial run, the variable crash_check should be set equal to 'pre' so that raw data is downloaded.
# ideally, the entire code should then run through without interruption.
# in possible post-crash runs, the crash_check can be set to anything else than 'pre', so that the data download step is skipped and model estimation picks up where it ended beforehand.
crash_check <- "post"

# get raw input data
if (crash_check == "pre"){
  source("01_us_get_data.R")
}

# run separable models
for (i in 1:2){
  set.seed(1917+i-1)

  toggle_nonsep <- 0
  source("02_us_run_models.R")
}

# run non-separable models
for (i in 1:2){

  set.seed(1917+i-1)

  toggle_nonsep <- 1
  source("02_us_run_models.R")
}

# extract results
source("03_us_extract_results.R")

# visualize results
source("04_us_viz.R")